package h0719;

import java.util.Scanner;
/**
  * @description 快递运输
  * @author 不知名帅哥
  * @date 2024/7/19 21:24
  * @version 1.0
*/
public class MaxParcels {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String[] weightsStr=sc.nextLine().split(",");
        int[] weights=new int[weightsStr.length];
        for (int i = 0; i < weightsStr.length; i++) {
            weights[i]=Integer.parseInt(weightsStr[i]);
        }
        int maxWeight=sc.nextInt();
        sc.close();
        int maxParcels=getMaxParcels(weights,maxWeight);
        System.out.println(maxParcels);
    }

    private static int getMaxParcels(int[] weights, int maxWeight) {
        int n = weights.length;
        int[][] dp = new int[n+1][maxWeight+1];     //dp[i][j]表示前i个快递，载重量为j时所能装的最大件数。
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= maxWeight; j++) {
                if (weights[i-1]<j){
                    //选择装这个快递还是不装这个快递
                    dp[i][j]=Math.max(dp[i-1][j],dp[i-1][j-weights[i-1]]+1);
                }
                else {
                    dp[i][j]=dp[i-1][j];
                }
            }
        }
        return dp[n][maxWeight];
    }
}
